package ${packagePrefix}.domain.service.impl;

import ${packagePrefix}.domain.entity.${domainObjectName};
import ${packagePrefix}.domain.service.${domainObjectName}Service;
import ${packagePrefix}.infrastructure.repository.${domainObjectName}Repository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

/**
 * ${tableComment!""} 服务实现类
 */
@Service
@RequiredArgsConstructor
public class ${domainObjectName}ServiceImpl implements ${domainObjectName}Service {

    private final ${domainObjectName}Repository ${domainObjectName?uncap_first}Repository;
    
    @Override
    @Transactional
    public Long create(${domainObjectName} ${domainObjectName?uncap_first}) {
        ${domainObjectName?uncap_first}Repository.save(${domainObjectName?uncap_first});
        return ${domainObjectName?uncap_first}.getId();
    }
    
    @Override
    public ${domainObjectName} findById(Long id) {
        Optional<${domainObjectName}> optional = ${domainObjectName?uncap_first}Repository.findById(id);
        return optional.orElse(null);
    }
    
    @Override
    public List<${domainObjectName}> findAll() {
        return ${domainObjectName?uncap_first}Repository.findAll();
    }
    
    @Override
    @Transactional
    public boolean update(${domainObjectName} ${domainObjectName?uncap_first}) {
        if (${domainObjectName?uncap_first}.getId() == null) {
            return false;
        }
        ${domainObjectName?uncap_first}Repository.save(${domainObjectName?uncap_first});
        return true;
    }
    
    @Override
    @Transactional
    public boolean deleteById(Long id) {
        if (id == null) {
            return false;
        }
        ${domainObjectName?uncap_first}Repository.deleteById(id);
        return true;
    }
} 